# -*- coding:utf-8 -*-

from pathlib import Path
import os


def file_exists(folder_path):
    if os.path.exists(folder_path) and os.path.isdir(folder_path):
        print("该文件夹存在")
    else:
        print("该文件夹不存在或者不是一个文件夹")


def get_folder_size(folder_path):
    total_size = 0
    for child in Path(folder_path).iterdir():
        if child.is_file():
            total_size += child.stat().st_size
        else:
            total_size += get_folder_size(child)
    return total_size


if __name__ == '__main__':
    folder_path = '../../../static'
    file_exists(folder_path)
    # print("文件夹大小为:", get_folder_size(folder_path), "字节")
    print("文件夹大小为:", get_folder_size(folder_path) / 1024 / 1024, "M")
